package com.itheima.day20.demo06;

import java.io.*;
import java.util.ArrayList;

/**
 * 8. 已知项目根目录下有一个stu.txt文件, 文件中记录的是学生的姓名和年龄,格式如下:
 * 瑞雯=23
 * 盲僧=24
 * 盖伦=41
 * 亚索=36
 * 需求:
 * a.将文件中的内容读取出来, 并存入到ArrayList<Student>集合中.
 * b.将年龄大于等于24的学生姓名，存入到D:\\student.txt中,格式为:
 * 盲僧
 * 盖伦
 * 亚索
 */
public class demo08 {
    public static final String SRC = "./homework/src/com/itheima/day20/demo06/stu.txt";
    public static final String DEST = "./homework/src/com/itheima/day20/demo06/student.txt";

    public static void main(String[] args) throws Exception {
        ArrayList<Student> list = new ArrayList<>();
        BufferedReader br = new BufferedReader(new FileReader(SRC));
        BufferedWriter bw = new BufferedWriter(new FileWriter(DEST));
        String s = null;
        while ((s = br.readLine()) != null) {
            String[] split = s.split("=");
            list.add(new Student(split[0], Integer.parseInt(split[1])));
        }
        Object clone = list.clone();
        System.out.println(clone == list);
        for (Student student : list) {
            if (student.getAge() >= 24) {
                bw.write(student.getName());
                bw.newLine();
            }
        }
        bw.flush();
        bw.close();
        br.close();
    }
}

class Student implements Cloneable {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Student() {
    }
}
